//
//  AbolishAppointmentController.m
//  HarmonizePub
//
//  Created by rzhy on 16/9/29.
//  Copyright © 2016年 Zy. All rights reserved.
//

#import "AbolishAppointmentController.h"
#import "Config.h"
#import "Patient.h"

@interface AbolishAppointmentController ()

@property (weak, nonatomic) IBOutlet UIView *mainView;
@property (weak, nonatomic) IBOutlet UILabel *depNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UILabel *doctorLabel;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *stateLabel;
@property (weak, nonatomic) IBOutlet UIButton *cancelButton;

@end

@implementation AbolishAppointmentController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"预约详情";
    [self setLabelText];
    self.mainView.layer.cornerRadius = 5.0f;
    self.mainView.layer.masksToBounds = YES;
    self.mainView.layer.borderWidth = 0.5f;
    self.mainView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.cancelButton.layer.cornerRadius = 5.0f;
    self.cancelButton.layer.masksToBounds = YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 取消预约
- (IBAction)abolishAppointmentEvent:(UIButton *)sender {
    NSDictionary *cookie = @{CookieVaule : [UserDefaultsTool stringForKey:XHToken]};
    NSDictionary *param = @{@"id" : @([Patient sharedPatient].id), @"hylsh" : _dataDict[@"hylsh"], @"yylsh" : _dataDict[@"yylsh"]};
    __unsafe_unretained AbolishAppointmentController *weakSelf = self;
    [HTTPSTool POSTRequestWithPath:XHCancelOrder cookie:cookie params:param success:^(NSDictionary * _Nonnull JSON) {
//        XHLog(@"取消预约 -> JSON: %@", JSON)
        [ZYToast showBottomText:@"预约取消成功!"];
        [weakSelf.navigationController popViewControllerAnimated:YES];
        if ([_delegate respondsToSelector:@selector(abolisht:abolishAppointmentDataWithDataDictionary:)])
            [_delegate abolisht:self abolishAppointmentDataWithDataDictionary:_dataDict];
    }];
}

#pragma mark - 设置label内容
- (void)setLabelText {
//    XHLog(@"dataDict: %@", _dataDict);
    self.depNameLabel.text = _dataDict[@"ksmc"];
    NSString *weekday   = [NSString stringWeekdayWithFromDate:[_dataDict[@"jzrq"] dateStringWithFormat:@"yyyy-MM-dd"] weekType:WeekdayDateStringTypeXingQi];
    self.dateLabel.text    = [NSString stringWithFormat:@"%@ %@", _dataDict[@"jzrq"], _dataDict[@"jzsj"]];
    self.timeLabel.text    = [NSString stringWithFormat:@"%@", _dataDict[@"sxwpb"]];
    self.doctorLabel.text  = _dataDict[@"ygdm"];
    self.nameLabel.text    = _dataDict[@"brxm"];
    self.stateLabel.text = _dataDict[@"result"];
}

@end
